package com.tangzhe.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 测试监听器
 */
public class ServletDemo2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取监听器中设置的request域属性
        String reqInitParam = request.getParameter("reqInitParam"); //之前的request已经销毁，所以为null
        System.out.println(reqInitParam);

        //获取监听器中设置的session域属性
        String sessionInitParam = (String) request.getSession().getAttribute("sessionInitParam");
        System.out.println(sessionInitParam);

        //获取监听器中context域的初始化属性
        String contextInitParam = (String) request.getServletContext().getInitParameter("contextInitParam");
        System.out.println(contextInitParam);

        //获取监听器中设置的context域属性
        Object contextParam = request.getServletContext().getAttribute("contextParam");
        System.out.println(contextParam);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}










